package com.efast.dmom.mgmt.service.demo.impl;
//package com.efast.emfg.dmom.service.demo.impl;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.UUID;
//
//import com.efast.cafe.framework.jdbc.JdbcDao;
//import com.efast.emfg.dmom.dao.demo.DemoOrderDao;
//import com.efast.emfg.dmom.dao.demo.DemoWorkOrderDao;
//import com.efast.emfg.dmom.entity.demo.DemoOrder;
//import com.efast.emfg.dmom.entity.demo.DemoWorkOrder;
//import com.efast.emfg.dmom.service.demo.DemoOrderService;
//import com.efast.emfg.dmom.utils.Assist;
//import com.eldfauto.Message;
//
//
//import org.eae.eldf.framework.util.ConfigUtil;
//import org.eae.eldf.framework.util.DateUtils;
//import org.eae.eldf.framework.util.JAXBUtil;
//import org.eae.eldf.framework.util.SpringWebUtils;
//import org.eae.eldf.msg.bean.wsmes.DemoWorkOrderDataBizContent;
//import org.eae.eldf.msg.bean.wsmes.WsDemoWorkOrderData;
//import org.eae.eldf.msg.remote.core.WSGatewayRemoteService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Service;
//@Service
//public class DemoOrderServiceImpl implements DemoOrderService{
//    @Autowired
//    private DemoOrderDao demoOrderDao;
//    
//    @Qualifier("jdbcDao")
//	@Autowired
//	private JdbcDao jdbcDao;
//    @Autowired
//    private DemoWorkOrderDao demoWorkOrderDao;
//    @Autowired
//	private WSGatewayRemoteService wSGatewayRemoteService;
//    
//    @Override
//    public long getDemoOrderRowCount(Assist assist){
//        return demoOrderDao.getDemoOrderRowCount(assist);
//    }
//    @Override
//    public List<DemoOrder> selectDemoOrder(Assist assist){
//        return demoOrderDao.selectDemoOrder(assist);
//    }
//    @Override
//    public DemoOrder selectDemoOrderByObj(DemoOrder obj){
//        return demoOrderDao.selectDemoOrderByObj(obj);
//    }
//    @Override
//    public DemoOrder selectDemoOrderById(Integer id){
//        return demoOrderDao.selectDemoOrderById(id);
//    }
//    @Override
//    public int insertDemoOrder(DemoOrder value){
//        return demoOrderDao.insertDemoOrder(value);
//    }
//    @Override
//    public int insertNonEmptyDemoOrder(DemoOrder value){
//        return demoOrderDao.insertNonEmptyDemoOrder(value);
//    }
//    @Override
//    public int insertDemoOrderByBatch(List<DemoOrder> value){
//        return demoOrderDao.insertDemoOrderByBatch(value);
//    }
//    @Override
//    public int deleteDemoOrderById(Integer id){
//        return demoOrderDao.deleteDemoOrderById(id);
//    }
//    @Override
//    public int deleteDemoOrder(Assist assist){
//        return demoOrderDao.deleteDemoOrder(assist);
//    }
//    @Override
//    public int updateDemoOrderById(DemoOrder enti){
//        return demoOrderDao.updateDemoOrderById(enti);
//    }
//    @Override
//    public int updateDemoOrder(DemoOrder value, Assist assist){
//        return demoOrderDao.updateDemoOrder(value,assist);
//    }
//    @Override
//    public int updateNonEmptyDemoOrderById(DemoOrder enti){
//        return demoOrderDao.updateNonEmptyDemoOrderById(enti);
//    }
//    @Override
//    public int updateNonEmptyDemoOrder(DemoOrder value, Assist assist){
//        return demoOrderDao.updateNonEmptyDemoOrder(value,assist);
//    }
//
//    public DemoOrderDao getDemoOrderDao() {
//        return this.demoOrderDao;
//    }
//
//    public void setDemoOrderDao(DemoOrderDao demoOrderDao) {
//        this.demoOrderDao = demoOrderDao;
//    }
//	@Override
//	public void downOrder(String orderNo) {
//		//保存订单信息
//		DemoOrder order = new DemoOrder();
//		order.setOrderNo(orderNo);
//		order.setOrderNum(1);
//		order.setCreateTime(new Date());
//		this.insertDemoOrder(order);	
//		//将订单号通过接口给威海公司
//		Message message = new Message();
//		DemoWorkOrder lot = new DemoWorkOrder();
//		lot.setOrderNo(orderNo);
//		message = getMessage("ALL_PL1","mesSystem","mesSystem1",lot);
//		wSGatewayRemoteService.doService(message);
//	}
//	@Override
//	public void generateWoInfo(String orderNo) {
//		// 威海自动生成工单信息
//		Assist assist = new Assist();
//		assist.setRequires(Assist.andEq("order_no", orderNo));
//		List<DemoWorkOrder> woList = demoWorkOrderDao.selectDemoWorkOrder(assist);
//		if(woList!=null&&woList.size()>0) {
//			DemoWorkOrder wo = woList.get(0);
//			String ASNcode = jdbcDao.executeProcGetCode("demo_work_order", "efast");
//			String lot = jdbcDao.executeProcGetCode("demo_plantone_lot", "efast");
//			wo.setWorkOrderNo(ASNcode);
//			wo.setLotNo(lot);
//			wo.setPlant("威海");
//			wo.setStatus("used");
//			wo.setOrderNo(orderNo);
//			demoWorkOrderDao.updateDemoWorkOrderById(wo);
//		}
//	}
//	@Override
//	public void proExe(String lotNo,String plant) {
//		String currentUser = SpringWebUtils.getRequestUser();
//		Assist assist = new Assist();
//		assist.setRequires(Assist.andEq("lot_no", lotNo));
//		List<DemoWorkOrder> lotList = demoWorkOrderDao.selectDemoWorkOrder(assist);
//		if(lotList!=null&&lotList.size()>0) {
//			DemoWorkOrder lot = lotList.get(0);
//			lot.setInBound(1);
//			lot.setInBoundTime(new Date());
//			lot.setOutBound(1);
//			lot.setOutBoundTime(new Date());
//			lot.setCreateTime(new Date());
//			lot.setCreateUser(currentUser);
//			if("plantOne".equals(plant)) {
//				lot.setOperation("OP1");
//			}else if("plantTwo".equals(plant)) {
//				lot.setOperation("OP2");
//			}
//			demoWorkOrderDao.updateDemoWorkOrderById(lot);
//			//给总公司发送生产执行数据
//			Message message = new Message();
//			Message lotMessage = new Message();
//			if("plantOne".equals(plant)) {
//				message = getMessage("PL1_ALL","mesSystem1","mesSystem",lot);
//				//接口：给下一公司发送lot数据
//				lotMessage = getMessage("PL1_PL2","mesSystem1","mesSystem2",lot);
//				wSGatewayRemoteService.doService(lotMessage);
//			}else if("plantTwo".equals(plant)) {
//				message = getMessage("PL1_ALL","mesSystem2","mesSystem",lot);
//			}
//			wSGatewayRemoteService.doService(message);
//		}
//	}
//	
//	@Override
//	public void lotTransform(String lotNo) {
//		//杭州公司批次转换
//		String currentUser = SpringWebUtils.getRequestUser();
//		Assist assist = new Assist();
//		assist.setRequires(Assist.andEq("parent_lot_no", lotNo));
//		String newLotNo = jdbcDao.executeProcGetCode("demo_planttwo_lot", "efast");
//		List<DemoWorkOrder> lotList = demoWorkOrderDao.selectDemoWorkOrder(assist);
//		if(lotList!=null&&lotList.size()>0) {
//			DemoWorkOrder lot = lotList.get(0);
//			lot.setLotNo(newLotNo);
//			lot.setParentLotNo(lotNo);
//			lot.setStatus("used");
//			lot.setPlant("杭州");
//			lot.setCreateTime(new Date());
//			lot.setCreateUser(currentUser);
//			demoWorkOrderDao.updateDemoWorkOrderById(lot);
//		}
//	}
//	
//	//接口
//	private Message getMessage(String bizCode,String msgFrom,String msgTo, DemoWorkOrder lot) {
//		ArrayList<String> reqToList = new ArrayList<>();
//		reqToList.add(msgTo);
//		Message message = new Message();
//		message.setMESSAGE_ID(UUID.randomUUID().toString());
//		message.setBIZ_CODE(bizCode);
//		message.setCREATE_TIME(DateUtils.dateToString(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));
//		message.setMESSAGE_FROM(msgFrom);
//		message.setMESSAGE_TO(reqToList);
//		message.setSEND_TIME(DateUtils.dateToString(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));
//		message.setVERSION("1");
//		DemoWorkOrderDataBizContent bizContent = new DemoWorkOrderDataBizContent();
//		WsDemoWorkOrderData data = getWsDemoWorkOrderData(lot);
//		List<WsDemoWorkOrderData> list = new ArrayList<>();
//		list.add(data);
//		bizContent.setWsDemoWorkOrder(list);
//		String content = JAXBUtil.marshal(bizContent);
//		message.setBIZ_CONTENT(content);
//		return message;
//	}
//	private WsDemoWorkOrderData getWsDemoWorkOrderData(DemoWorkOrder lot) {
//		WsDemoWorkOrderData data = new WsDemoWorkOrderData();
//		data.setOrderNo(lot.getOrderNo());
//		data.setWorkOrderNo(lot.getWorkOrderNo());
//		data.setLotNo(lot.getLotNo());
//		data.setParentLotNo(lot.getParentLotNo());
//		data.setOperation(lot.getOperation());
//		data.setInBound(lot.getInBound());
//		data.setInBoundTime(lot.getInBoundTime());
//		data.setOutBound(lot.getOutBound());
//		data.setOutBoundTime(lot.getOutBoundTime());
//		data.setPlant(lot.getPlant());
//		return data;
//	}
//	@Override
//	public List<DemoWorkOrder> getNewOrderNo() {
//		// 获取新的订单号
//		Assist assist = new Assist();
//		assist.setRequires(Assist.andEq("status", "create"));
//		return demoWorkOrderDao.selectDemoWorkOrder(assist);
//	}
//	@Override
//	public List<DemoWorkOrder> getNewLotNo() {
//		// 获取新的lot编号
//		Assist assist = new Assist();
//		assist.setRequires(Assist.andEq("status", "create"));
//		return demoWorkOrderDao.selectDemoWorkOrder(assist);
//	}
//}